if (!require("pacman")) install.packages("pacman")
pacman::p_load("weights", "interactions", "cjoint", "plm", "interactions", "jtools", "stats", "miceadds", "broom", "RColorBrewer", "ggstatsplot", "ggpubr", "stargazer", "sandwich", "hrbrthemes", "rms", "interplot", "coefplot", "gmodels", "car", "lattice","foreign", "ggplot2", "MASS", "Hmisc", "reshape2", "oddsratio", "tidyr", "psych", "dplyr", "tidyverse", "ggthemes", "readtext", "RCurl", "topicmodels", "stm", "wordcloud", "tm", "tidy", "broom")

ds <- read.csv("Gubitz_clean_ds.csv", stringsAsFactors = F)

table(ds$race)
table(ds$condition)

table(ds.black$condition)

ds.white <- dplyr::filter(ds, race == "white")
ds.black <- dplyr::filter(ds, race == "black")
ds.black.control <- dplyr::filter(ds.black, condition == "control")
ds.white.control <- dplyr::filter(ds.white, condition == "control")

#demographics



#information for table 1
#more disruptive activities
t.test(ds.black.control$blocktraffic.uncivil, ds.white.control$blocktraffic.uncivil)
t.test(ds.black.control$property.uncivil, ds.white.control$property.uncivil)
t.test(ds.black.control$graffiti.uncivil, ds.white.control$graffiti.uncivil)
t.test(ds.black.control$interrupt.uncivil, ds.white.control$interrupt.uncivil)
t.test(ds.black.control$occupy.uncivil, ds.white.control$occupy.uncivil)
t.test(ds.black.control$punch.uncivil, ds.white.control$punch.uncivil)
t.test(ds.black.control$throw.uncivil, ds.white.control$throw.uncivil)
t.test(ds.black.control$threat.uncivil, ds.white.control$threat.uncivil)
#less disruptive activities
t.test(ds.black.control$boycott.uncivil, ds.white.control$boycott.uncivil)
t.test(ds.black.control$camp.uncivil, ds.white.control$camp.uncivil)
t.test(ds.black.control$vigil.uncivil, ds.white.control$vigil.uncivil)
t.test(ds.black.control$chant.uncivil, ds.white.control$chant.uncivil)
t.test(ds.black.control$lawsuit.uncivil, ds.white.control$lawsuit.uncivil)
t.test(ds.black.control$leaflet.uncivil, ds.white.control$leaflet.uncivil)
t.test(ds.black.control$march.uncivil, ds.white.control$march.uncivil)
t.test(ds.black.control$parade.uncivil, ds.white.control$parade.uncivil)
t.test(ds.black.control$petition.uncivil, ds.white.control$petition.uncivil)
t.test(ds.black.control$picket.uncivil, ds.white.control$picket.uncivil)
t.test(ds.black.control$sitin.uncivil, ds.white.control$sitin.uncivil)
t.test(ds.black.control$knee.uncivil, ds.white.control$knee.uncivil)

#overall, average effect

long.ds.1 <- pivot_longer(ds, cols = ends_with(".uncivil"), names_to = "activity", values_to = "perception") %>% 
  mutate(activity = str_remove(activity, ".uncivil$")) %>% 
  mutate(activity = as.factor(activity))

long.ds.2 <- pivot_longer(ds, cols = ends_with(".participate"), names_to = "activity", values_to = "participate") %>% 
  mutate(activity = str_remove(activity, ".participate$")) %>% 
  mutate(activity = as.factor(activity))

long.ds.1 <- long.ds.1 %>% 
  mutate(disruptive = case_when(activity == "blocktraffic" | activity == "property" | activity == "graffiti" | activity == "interrupt" | activity == "occupy"  | activity == "punch"  | activity == "throw" | activity == "threat" ~ "more disruptive", 
                                activity == "boycott" | activity == "camp" | activity == "vigil" | activity == "chant" | activity == "lawsuit" | activity == "leaflet" | activity == "march" | activity == "parade" | activity == "petition" | activity == "picket" | activity == "sitin" | activity == "knee" ~ "less disruptive") %>% as.factor())
long.ds.2 <- long.ds.2 %>% 
  mutate(disruptive = case_when(activity == "blocktraffic" | activity == "property" | activity == "graffiti" | activity == "interrupt" | activity == "occupy"  | activity == "punch"  | activity == "throw" | activity == "threat" ~ "more disruptive", 
                                activity == "boycott" | activity == "camp" | activity == "vigil" | activity == "chant" | activity == "lawsuit" | activity == "leaflet" | activity == "march" | activity == "parade" | activity == "petition" | activity == "picket" | activity == "sitin" | activity == "knee" ~ "less disruptive") %>% as.factor())

ate1 <- lm(perception ~ condition + activity, data = long.ds.1)
ate2 <- lm(perception ~ condition + activity, data = long.ds.1, subset = race == "black")
ate3 <- lm(perception ~ condition + activity, data = long.ds.1, subset = race == "white")

stargazer(ate1, ate2, ate3, type = "text", out = "tablei1.html")

ate4 <- lm(participate ~ condition + activity, data = long.ds.2)
ate5 <- lm(participate ~ condition + activity, data = long.ds.2, subset = race == "black")
ate6 <- lm(participate ~ condition + activity, data = long.ds.2, subset = race == "white")

stargazer(ate4, ate5, ate6, type = "text", out = "tablei2.html")

ate7 <- lm(perception ~ condition + disruptive, data = long.ds.1)
ate8 <- lm(perception ~ condition + disruptive, data = long.ds.1, subset = race == "black")
ate9 <- lm(perception ~ condition + disruptive, data = long.ds.1, subset = race == "white")

stargazer(ate7, ate8, ate9, type = "text")

ate10 <- lm(participate ~ condition + disruptive, data = long.ds.2)
ate11 <- lm(participate ~ condition + disruptive, data = long.ds.2, subset = race == "black")
ate12 <- lm(participate ~ condition + disruptive, data = long.ds.2, subset = race == "white")

stargazer(ate10, ate11, ate12, type = "text")

#new figure 2 (difference in means plot)
black.sqrt <- sqrt(691)
white.sqrt <- sqrt(736)

modelcoef = mean(ds.black.control$blocktraffic.uncivil, na.rm = T)
ylo = mean(ds.black.control$blocktraffic.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$blocktraffic.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$blocktraffic.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$blocktraffic.uncivil, na.rm = T)/black.sqrt)) 
names = "Blocking traffic***"
type = "More Disruptive"
race = "Black"
dfplot81 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$blocktraffic.uncivil, na.rm = T)
ylo = mean(ds.white.control$blocktraffic.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$blocktraffic.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$blocktraffic.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$blocktraffic.uncivil, na.rm = T)/white.sqrt)) 
names = "Blocking traffic***"
type = "More Disruptive"
race = "White"
dfplot82 = data.frame(names, modelcoef, ylo, yhi, race, type)
dfplot82

modelcoef = mean(ds.black.control$property.uncivil, na.rm = T)
ylo = mean(ds.black.control$property.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$property.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$property.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$property.uncivil, na.rm = T)/black.sqrt)) 
names = "Damaging property***"
type = "More Disruptive"
race = "Black"
dfplot83 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$property.uncivil, na.rm = T)
ylo = mean(ds.white.control$property.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$property.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$property.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$property.uncivil, na.rm = T)/white.sqrt)) 
names = "Damaging property***"
type = "More Disruptive"
race = "White"
dfplot84 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$graffiti.uncivil, na.rm = T)
ylo = mean(ds.black.control$graffiti.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$graffiti.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$graffiti.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$graffiti.uncivil, na.rm = T)/black.sqrt)) 
names = "Graffiti***"
type = "More Disruptive"
race = "Black"
dfplot85 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$graffiti.uncivil, na.rm = T)
ylo = mean(ds.white.control$graffiti.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$graffiti.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$graffiti.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$graffiti.uncivil, na.rm = T)/white.sqrt)) 
names = "Graffiti***"
type = "More Disruptive"
race = "White"
dfplot86 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$interrupt.uncivil, na.rm = T)
ylo = mean(ds.black.control$interrupt.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$interrupt.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$interrupt.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$interrupt.uncivil, na.rm = T)/black.sqrt)) 
names = "Interrrupting public event***"
type = "More Disruptive"
race = "Black"
dfplot87 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$interrupt.uncivil, na.rm = T)
ylo = mean(ds.white.control$interrupt.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$interrupt.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$interrupt.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$interrupt.uncivil, na.rm = T)/white.sqrt)) 
names = "Interrrupting public event***"
type = "More Disruptive"
race = "White"
dfplot88 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$occupy.uncivil, na.rm = T)
ylo = mean(ds.black.control$occupy.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$occupy.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$occupy.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$occupy.uncivil, na.rm = T)/black.sqrt)) 
names = "Occupying private property***"
type = "More Disruptive"
race = "Black"
dfplot89 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$occupy.uncivil, na.rm = T)
ylo = mean(ds.white.control$occupy.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$occupy.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$occupy.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$occupy.uncivil, na.rm = T)/white.sqrt)) 
names = "Occupying private property***"
type = "More Disruptive"
race = "White"
dfplot90 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$punch.uncivil, na.rm = T)
ylo = mean(ds.black.control$punch.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$punch.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$punch.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$punch.uncivil, na.rm = T)/black.sqrt)) 
names = "Punching***"
type = "More Disruptive"
race = "Black"
dfplot91 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$punch.uncivil, na.rm = T)
ylo = mean(ds.white.control$punch.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$punch.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$punch.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$punch.uncivil, na.rm = T)/white.sqrt)) 
names = "Punching***"
type = "More Disruptive"
race = "White"
dfplot92 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$throw.uncivil, na.rm = T)
ylo = mean(ds.black.control$throw.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$throw.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$throw.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$throw.uncivil, na.rm = T)/black.sqrt)) 
names = "Throwing objects**"
type = "More Disruptive"
race = "Black"
dfplot93 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$throw.uncivil, na.rm = T)
ylo = mean(ds.white.control$throw.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$throw.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$throw.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$throw.uncivil, na.rm = T)/white.sqrt)) 
names = "Throwing objects**"
type = "More Disruptive"
race = "White"
dfplot94 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$threat.uncivil, na.rm = T)
ylo = mean(ds.black.control$threat.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$threat.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$threat.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$threat.uncivil, na.rm = T)/black.sqrt)) 
names = "Verbal threats**"
type = "More Disruptive"
race = "Black"
dfplot95 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$threat.uncivil, na.rm = T)
ylo = mean(ds.white.control$threat.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$threat.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$threat.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$threat.uncivil, na.rm = T)/white.sqrt)) 
names = "Verbal threats**"
type = "More Disruptive"
race = "White"
dfplot96 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$boycott.uncivil, na.rm = T)
ylo = mean(ds.black.control$boycott.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$boycott.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$boycott.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$boycott.uncivil, na.rm = T)/black.sqrt)) 
names = "Boycotts**"
type = "Less Disruptive"
race = "Black"
dfplot97 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$boycott.uncivil, na.rm = T)
ylo = mean(ds.white.control$boycott.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$boycott.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$boycott.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$boycott.uncivil, na.rm = T)/white.sqrt)) 
names = "Boycotts**"
type = "Less Disruptive"
race = "White"
dfplot98 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$camp.uncivil, na.rm = T)
ylo = mean(ds.black.control$camp.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$camp.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$camp.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$camp.uncivil, na.rm = T)/black.sqrt)) 
names = "Camping on public property***"
type = "Less Disruptive"
race = "Black"
dfplot99 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$camp.uncivil, na.rm = T)
ylo = mean(ds.white.control$camp.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$camp.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$camp.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$camp.uncivil, na.rm = T)/white.sqrt)) 
names = "Camping on public property***"
type = "Less Disruptive"
race = "White"
dfplot100 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$vigil.uncivil, na.rm = T)
ylo = mean(ds.black.control$vigil.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$vigil.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$vigil.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$vigil.uncivil, na.rm = T)/black.sqrt)) 
names = "Candlelight vigils"
type = "Less Disruptive"
race = "Black"
dfplot101 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$vigil.uncivil, na.rm = T)
ylo = mean(ds.white.control$vigil.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$vigil.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$vigil.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$vigil.uncivil, na.rm = T)/white.sqrt)) 
names = "Candlelight vigils"
type = "Less Disruptive"
race = "White"
dfplot102 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$chant.uncivil, na.rm = T)
ylo = mean(ds.black.control$chant.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$chant.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$chant.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$chant.uncivil, na.rm = T)/black.sqrt)) 
names = "Chanting***"
type = "Less Disruptive"
race = "Black"
dfplot103 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$chant.uncivil, na.rm = T)
ylo = mean(ds.white.control$chant.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$chant.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$chant.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$chant.uncivil, na.rm = T)/white.sqrt)) 
names = "Chanting***"
type = "Less Disruptive"
race = "White"
dfplot104 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$lawsuit.uncivil, na.rm = T)
ylo = mean(ds.black.control$lawsuit.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$lawsuit.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$lawsuit.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$lawsuit.uncivil, na.rm = T)/black.sqrt)) 
names = "Lawsuits***"
type = "Less Disruptive"
race = "Black"
dfplot105 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$lawsuit.uncivil, na.rm = T)
ylo = mean(ds.white.control$lawsuit.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$lawsuit.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$lawsuit.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$lawsuit.uncivil, na.rm = T)/white.sqrt)) 
names = "Lawsuits***"
type = "Less Disruptive"
race = "White"
dfplot106 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$leaflet.uncivil, na.rm = T)
ylo = mean(ds.black.control$leaflet.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$leaflet.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$leaflet.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$leaflet.uncivil, na.rm = T)/black.sqrt)) 
names = "Leaflets***"
type = "Less Disruptive"
race = "Black"
dfplot107 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$leaflet.uncivil, na.rm = T)
ylo = mean(ds.white.control$leaflet.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$leaflet.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$leaflet.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$leaflet.uncivil, na.rm = T)/white.sqrt)) 
names = "Leaflets***"
type = "Less Disruptive"
race = "White"
dfplot108 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$march.uncivil, na.rm = T)
ylo = mean(ds.black.control$march.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$march.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$march.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$march.uncivil, na.rm = T)/black.sqrt)) 
names = "Marching***"
type = "Less Disruptive"
race = "Black"
dfplot109 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$march.uncivil, na.rm = T)
ylo = mean(ds.white.control$march.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$march.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$march.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$march.uncivil, na.rm = T)/white.sqrt)) 
names = "Marching***"
type = "Less Disruptive"
race = "White"
dfplot110 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$parade.uncivil, na.rm = T)
ylo = mean(ds.black.control$parade.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$parade.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$parade.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$parade.uncivil, na.rm = T)/black.sqrt)) 
names = "Parades"
type = "Less Disruptive"
race = "Black"
dfplot111 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$parade.uncivil, na.rm = T)
ylo = mean(ds.white.control$parade.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$parade.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$parade.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$parade.uncivil, na.rm = T)/white.sqrt)) 
names = "Parades"
type = "Less Disruptive"
race = "White"
dfplot112 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$petition.uncivil, na.rm = T)
ylo = mean(ds.black.control$petition.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$petition.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$petition.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$petition.uncivil, na.rm = T)/black.sqrt)) 
names = "Petitions"
type = "Less Disruptive"
race = "Black"
dfplot113 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$petition.uncivil, na.rm = T)
ylo = mean(ds.white.control$petition.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$petition.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$petition.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$petition.uncivil, na.rm = T)/white.sqrt)) 
names = "Petitions"
type = "Less Disruptive"
race = "White"
dfplot114 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$picket.uncivil, na.rm = T)
ylo = mean(ds.black.control$picket.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$picket.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$picket.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$picket.uncivil, na.rm = T)/black.sqrt)) 
names = "Picket lines***"
type = "Less Disruptive"
race = "Black"
dfplot115 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$picket.uncivil, na.rm = T)
ylo = mean(ds.white.control$picket.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$picket.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$picket.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$picket.uncivil, na.rm = T)/white.sqrt)) 
names = "Picket lines***"
type = "Less Disruptive"
race = "White"
dfplot116 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$sitin.uncivil, na.rm = T)
ylo = mean(ds.black.control$sitin.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$sitin.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$sitin.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$sitin.uncivil, na.rm = T)/black.sqrt)) 
names = "Sit-ins***"
type = "Less Disruptive"
race = "Black"
dfplot117 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$sitin.uncivil, na.rm = T)
ylo = mean(ds.white.control$sitin.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$sitin.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$sitin.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$sitin.uncivil, na.rm = T)/white.sqrt)) 
names = "Sit-ins***"
type = "Less Disruptive"
race = "White"
dfplot118 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.black.control$knee.uncivil, na.rm = T)
ylo = mean(ds.black.control$knee.uncivil, na.rm = T) - (1.96*(sd(ds.black.control$knee.uncivil, na.rm = T)/black.sqrt)) 
yhi = mean(ds.black.control$knee.uncivil, na.rm = T) + (1.96*(sd(ds.black.control$knee.uncivil, na.rm = T)/black.sqrt)) 
names = "Taking a knee***"
type = "Less Disruptive"
race = "Black"
dfplot119 = data.frame(names, modelcoef, ylo, yhi, race, type)

modelcoef = mean(ds.white.control$knee.uncivil, na.rm = T)
ylo = mean(ds.white.control$knee.uncivil, na.rm = T) - (1.96*(sd(ds.white.control$knee.uncivil, na.rm = T)/white.sqrt)) 
yhi = mean(ds.white.control$knee.uncivil, na.rm = T) + (1.96*(sd(ds.white.control$knee.uncivil, na.rm = T)/white.sqrt)) 
names = "Taking a knee***"
type = "Less Disruptive"
race = "White"
dfplot120 = data.frame(names, modelcoef, ylo, yhi, race, type)


test.df <- rbind(dfplot81, dfplot82, dfplot83, dfplot84, dfplot85, dfplot86, dfplot87, dfplot88,
                dfplot89, dfplot90, dfplot91, dfplot92, dfplot93, dfplot94, dfplot95, dfplot96,
                dfplot97, dfplot98, dfplot99, dfplot100, dfplot101, dfplot102, dfplot103, dfplot104,
                dfplot105, dfplot106, dfplot107, dfplot108, dfplot109, dfplot110, dfplot111, dfplot112,
                dfplot113, dfplot114, dfplot115, dfplot116, dfplot117, dfplot118, dfplot119, dfplot120)

test.df

# Create first half of figure
figure2a <- filter(test.df, type=="Less Disruptive") %>% 
  ggplot(aes(x=names, y=modelcoef, group=race, fill=race, shape=race)) + 
  geom_point(position = position_dodge(0.7), size=2.5, show.legend = F) +
  geom_errorbar(aes(ymin = ylo, ymax = yhi), width = .1, position = position_dodge(0.7)) +
  theme_fivethirtyeight() + 
  coord_flip() + 
  geom_hline(lty=2, yintercept = 0) + 
  ylim(0.0,0.5)


# Create second half of figure
# Note only the lower half contains the caption
figure2b <- filter(test.df, type=="More Disruptive") %>% 
  ggplot(aes(x=names, y=modelcoef, group=race, fill=race, shape=race)) + 
  geom_point(position = position_dodge(0.6), size=2.5) +
  geom_errorbar(aes(ymin = ylo, ymax = yhi), width = .1, position = position_dodge(0.6)) +
  theme_fivethirtyeight() + 
  coord_flip() + 
  geom_hline(lty=2, yintercept = 0) + 
  labs(caption = "Note: Bars represent 95% confidence intervals; Corresponding table can be found in Appendix B",
       y = "Perception of incivility (low to high)") + 
  ylim(0.45,0.95)


# Combine figure halves using ggarrange as two rows, add labels, save as jpg
ggarrange(figure2a, figure2b, nrow=2, labels=c("Less Disruptive","More Disruptive")) + 
  ggsave("figure2.jpg", device = "jpeg", dpi = 320, width = 7.5, height = 9.5, units = "in")

#information for appendix
#more disruptive activities
t.test(ds.black.control$blocktraffic.participate, ds.white.control$blocktraffic.participate)
t.test(ds.black.control$property.participate, ds.white.control$property.participate)
t.test(ds.black.control$graffiti.participate, ds.white.control$graffiti.participate)
t.test(ds.black.control$interrupt.participate, ds.white.control$interrupt.participate)
t.test(ds.black.control$occupy.participate, ds.white.control$occupy.participate)
t.test(ds.black.control$punch.participate, ds.white.control$punch.participate)
t.test(ds.black.control$throw.participate, ds.white.control$throw.participate)
t.test(ds.black.control$threat.participate, ds.white.control$threat.participate)
#less disruptive activities
t.test(ds.black.control$boycott.participate, ds.white.control$boycott.participate)
t.test(ds.black.control$camp.participate, ds.white.control$camp.participate)
t.test(ds.black.control$vigil.participate, ds.white.control$vigil.participate)
t.test(ds.black.control$chant.participate, ds.white.control$chant.participate)
t.test(ds.black.control$lawsuit.participate, ds.white.control$lawsuit.participate)
t.test(ds.black.control$leaflet.participate, ds.white.control$leaflet.participate)
t.test(ds.black.control$march.participate, ds.white.control$march.participate)
t.test(ds.black.control$parade.participate, ds.white.control$parade.participate)
t.test(ds.black.control$petition.participate, ds.white.control$petition.participate)
t.test(ds.black.control$picket.participate, ds.white.control$picket.participate)
t.test(ds.black.control$sitin.participate, ds.white.control$sitin.participate)
t.test(ds.black.control$knee.participate, ds.white.control$knee.participate)

#Figure 3
reg1 <- lm(picket.uncivil ~ condition, data = ds.black)
reg2 <- lm(chant.uncivil ~ condition, data = ds.black)
reg3 <- lm(march.uncivil ~ condition, data = ds.black)
reg4 <- lm(punch.uncivil ~ condition, data = ds.black)
reg5 <- lm(interrupt.uncivil ~ condition, data = ds.black)
reg6 <- lm(parade.uncivil ~ condition, data = ds.black)
reg7 <- lm(knee.uncivil ~ condition, data = ds.black)
reg8 <- lm(petition.uncivil ~ condition, data = ds.black)
reg9 <- lm(property.uncivil ~ condition, data = ds.black)
reg10 <- lm(throw.uncivil ~ condition, data = ds.black)
reg11 <- lm(sitin.uncivil ~ condition, data = ds.black)
reg12 <- lm(blocktraffic.uncivil ~ condition, data = ds.black)
reg13 <- lm(occupy.uncivil ~ condition, data = ds.black)
reg14 <- lm(graffiti.uncivil ~ condition, data = ds.black)
reg15 <- lm(camp.uncivil ~ condition, data = ds.black)
reg16 <- lm(lawsuit.uncivil ~ condition, data = ds.black)
reg17 <- lm(boycott.uncivil ~ condition, data = ds.black)
reg18 <- lm(vigil.uncivil ~ condition, data = ds.black)
reg19 <- lm(threat.uncivil ~ condition, data = ds.black)
reg20 <- lm(leaflet.uncivil ~ condition, data = ds.black)

reg21 <- lm(picket.uncivil ~ condition, data = ds.white)
reg22 <- lm(chant.uncivil ~ condition, data = ds.white)
reg23 <- lm(march.uncivil ~ condition, data = ds.white)
reg24 <- lm(punch.uncivil ~ condition, data = ds.white)
reg25 <- lm(interrupt.uncivil ~ condition, data = ds.white)
reg26 <- lm(parade.uncivil ~ condition, data = ds.white)
reg27 <- lm(knee.uncivil ~ condition, data = ds.white)
reg28 <- lm(petition.uncivil ~ condition, data = ds.white)
reg29 <- lm(property.uncivil ~ condition, data = ds.white)
reg30 <- lm(throw.uncivil ~ condition, data = ds.white)
reg31 <- lm(sitin.uncivil ~ condition, data = ds.white)
reg32 <- lm(blocktraffic.uncivil ~ condition, data = ds.white)
reg33 <- lm(occupy.uncivil ~ condition, data = ds.white)
reg34 <- lm(graffiti.uncivil ~ condition, data = ds.white)
reg35 <- lm(camp.uncivil ~ condition, data = ds.white)
reg36 <- lm(lawsuit.uncivil ~ condition, data = ds.white)
reg37 <- lm(boycott.uncivil ~ condition, data = ds.white)
reg38 <- lm(vigil.uncivil ~ condition, data = ds.white)
reg39 <- lm(threat.uncivil ~ condition, data = ds.white)
reg40 <- lm(leaflet.uncivil ~ condition, data = ds.white)

stargazer(reg4, reg5, reg9, reg10, reg12, reg13, reg14, reg19, type = "text", out = "blackuncivil.html")
stargazer(reg24, reg25, reg29, reg30, reg32, reg33, reg34, reg39, type = "text", out = "whiteuncivil.html")

lmp <- function (modelobject) {
  if (class(modelobject) != "lm") stop("Not an object of class 'lm' ")
  f <- summary(modelobject)$fstatistic
  p <- pf(f[1],f[2],f[3],lower.tail=F)
  attributes(p) <- NULL
  return(p)
}

p.value.list.1 <- c(lmp(reg4), lmp(reg5), lmp(reg9), lmp(reg10), lmp(reg12), lmp(reg13), lmp(reg14), lmp(reg19))

p.value.list.2 <- c(lmp(reg24), lmp(reg25), lmp(reg29), lmp(reg30), lmp(reg32), lmp(reg33), lmp(reg34), lmp(reg39))             
                    
round(p.value.list.1, digits = 4)
round(p.value.list.2, digits = 4)

multi.correct.1 <- p.adjust(p.value.list.1, method = "bonferroni", n = 8)
multi.correct.2 <- p.adjust(p.value.list.2, method = "bonferroni", n = 8)

round(multi.correct.1, digits = 4)
round(multi.correct.2, digits = 4)

modelcoef = summary(reg1)$coefficients[1:length(reg1$coefficients), 1]
modelse = as.vector(coeftest(reg1)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Picket Lines")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot1 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot1 = dfplot1[-c(1),]

modelcoef = summary(reg21)$coefficients[1:length(reg21$coefficients), 1]
modelse = as.vector(coeftest(reg21)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Picket Lines***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot2 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot2 = dfplot2[-c(1),]

modelcoef = summary(reg2)$coefficients[1:length(reg2$coefficients), 1]
modelse = as.vector(coeftest(reg2)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Chanting")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot3 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot3 = dfplot3[-c(1),]

modelcoef = summary(reg22)$coefficients[1:length(reg22$coefficients), 1]
modelse = as.vector(coeftest(reg22)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Chanting***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot4 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot4 = dfplot4[-c(1),]

modelcoef = summary(reg3)$coefficients[1:length(reg3$coefficients), 1]
modelse = as.vector(coeftest(reg3)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Marching")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot5 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot5 = dfplot5[-c(1),]

modelcoef = summary(reg23)$coefficients[1:length(reg23$coefficients), 1]
modelse = as.vector(coeftest(reg23)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Marching**")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot6 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot6 = dfplot6[-c(1),]

modelcoef = summary(reg4)$coefficients[1:length(reg4$coefficients), 1]
modelse = as.vector(coeftest(reg4)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Punching***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot7 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot7 = dfplot7[-c(1),]

modelcoef = summary(reg24)$coefficients[1:length(reg24$coefficients), 1]
modelse = as.vector(coeftest(reg24)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Punching")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot8 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot8 = dfplot8[-c(1),]

modelcoef = summary(reg5)$coefficients[1:length(reg5$coefficients), 1]
modelse = as.vector(coeftest(reg5)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Interrupting public event***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot9 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot9 = dfplot9[-c(1),]

modelcoef = summary(reg25)$coefficients[1:length(reg25$coefficients), 1]
modelse = as.vector(coeftest(reg25)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Interrupting public event***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot10 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot10 = dfplot10[-c(1),]

modelcoef = summary(reg6)$coefficients[1:length(reg6$coefficients), 1]
modelse = as.vector(coeftest(reg6)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Parades*")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot11 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot11 = dfplot11[-c(1),]

modelcoef = summary(reg26)$coefficients[1:length(reg26$coefficients), 1]
modelse = as.vector(coeftest(reg26)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Parades")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot12 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot12 = dfplot12[-c(1),]

stargazer(reg46, type = "text")

modelcoef = summary(reg7)$coefficients[1:length(reg7$coefficients), 1]
modelse = as.vector(coeftest(reg7)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Taking a knee")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot13 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot13 = dfplot13[-c(1),]

modelcoef = summary(reg27)$coefficients[1:length(reg27$coefficients), 1]
modelse = as.vector(coeftest(reg27)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Taking a knee")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot14 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot14 = dfplot14[-c(1),]

modelcoef = summary(reg8)$coefficients[1:length(reg8$coefficients), 1]
modelse = as.vector(coeftest(reg8)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Petitions")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot15 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot15 = dfplot15[-c(1),]

modelcoef = summary(reg28)$coefficients[1:length(reg28$coefficients), 1]
modelse = as.vector(coeftest(reg28)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Petitions")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot16 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot16 = dfplot16[-c(1),]

modelcoef = summary(reg9)$coefficients[1:length(reg9$coefficients), 1]
modelse = as.vector(coeftest(reg9)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Damaging property***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot17 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot17 = dfplot17[-c(1),]

modelcoef = summary(reg29)$coefficients[1:length(reg29$coefficients), 1]
modelse = as.vector(coeftest(reg29)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Damaging property")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot18 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot18 = dfplot18[-c(1),]

modelcoef = summary(reg10)$coefficients[1:length(reg10$coefficients), 1]
modelse = as.vector(coeftest(reg10)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Throwing objects***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot19 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot19 = dfplot19[-c(1),]

modelcoef = summary(reg30)$coefficients[1:length(reg30$coefficients), 1]
modelse = as.vector(coeftest(reg30)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Throwing objects")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot20 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot20 = dfplot20[-c(1),]

modelcoef = summary(reg11)$coefficients[1:length(reg11$coefficients), 1]
modelse = as.vector(coeftest(reg11)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Sit-ins")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot21 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot21 = dfplot21[-c(1),]

modelcoef = summary(reg31)$coefficients[1:length(reg31$coefficients), 1]
modelse = as.vector(coeftest(reg31)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Sit-ins***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot22 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot22 = dfplot22[-c(1),]

modelcoef = summary(reg12)$coefficients[1:length(reg12$coefficients), 1]
modelse = as.vector(coeftest(reg12)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Blocking traffic***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot23 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot23 = dfplot23[-c(1),]

modelcoef = summary(reg32)$coefficients[1:length(reg32$coefficients), 1]
modelse = as.vector(coeftest(reg32)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Blocking traffic***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot24 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot24 = dfplot24[-c(1),]

modelcoef = summary(reg13)$coefficients[1:length(reg13$coefficients), 1]
modelse = as.vector(coeftest(reg13)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Occupying private property**")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot25 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot25 = dfplot25[-c(1),]

modelcoef = summary(reg33)$coefficients[1:length(reg33$coefficients), 1]
modelse = as.vector(coeftest(reg33)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Occupying private property")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot26 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot26 = dfplot26[-c(1),]

modelcoef = summary(reg14)$coefficients[1:length(reg14$coefficients), 1]
modelse = as.vector(coeftest(reg14)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Graffiti***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot27 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot27 = dfplot27[-c(1),]

modelcoef = summary(reg34)$coefficients[1:length(reg34$coefficients), 1]
modelse = as.vector(coeftest(reg34)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Graffiti")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot28 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot28 = dfplot28[-c(1),]

modelcoef = summary(reg15)$coefficients[1:length(reg15$coefficients), 1]
modelse = as.vector(coeftest(reg15)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Camping on public property*")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot29 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot29 = dfplot29[-c(1),]

modelcoef = summary(reg35)$coefficients[1:length(reg35$coefficients), 1]
modelse = as.vector(coeftest(reg35)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Camping on public property***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot30 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot30 = dfplot30[-c(1),]

modelcoef = summary(reg16)$coefficients[1:length(reg16$coefficients), 1]
modelse = as.vector(coeftest(reg16)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Lawsuits")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot31 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot31 = dfplot31[-c(1),]

modelcoef = summary(reg36)$coefficients[1:length(reg36$coefficients), 1]
modelse = as.vector(coeftest(reg36)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Lawsuits***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot32 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot32 = dfplot32[-c(1),]

modelcoef = summary(reg17)$coefficients[1:length(reg17$coefficients), 1]
modelse = as.vector(coeftest(reg17)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Boycotts")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot33 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot33 = dfplot33[-c(1),]

modelcoef = summary(reg37)$coefficients[1:length(reg37$coefficients), 1]
modelse = as.vector(coeftest(reg37)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Boycotts**")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot34 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot34 = dfplot34[-c(1),]

modelcoef = summary(reg18)$coefficients[1:length(reg18$coefficients), 1]
modelse = as.vector(coeftest(reg18)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Candlelight vigils")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot35 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot35 = dfplot35[-c(1),]

modelcoef = summary(reg38)$coefficients[1:length(reg38$coefficients), 1]
modelse = as.vector(coeftest(reg38)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Candlelight vigils")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot36 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot36 = dfplot36[-c(1),]

modelcoef = summary(reg19)$coefficients[1:length(reg19$coefficients), 1]
modelse = as.vector(coeftest(reg19)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Verbal threats**")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot37 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot37 = dfplot37[-c(1),]

modelcoef = summary(reg39)$coefficients[1:length(reg39$coefficients), 1]
modelse = as.vector(coeftest(reg39)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Verbal threats")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot38 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot38 = dfplot38[-c(1),]

modelcoef = summary(reg20)$coefficients[1:length(reg20$coefficients), 1]
modelse = as.vector(coeftest(reg20)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Leaflets")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot39 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot39 = dfplot39[-c(1),]

modelcoef = summary(reg40)$coefficients[1:length(reg40$coefficients), 1]
modelse = as.vector(coeftest(reg40)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Leaflets")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot40 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot40 = dfplot40[-c(1),]

test.df <- rbind(dfplot37, dfplot19, dfplot13, dfplot21,
                  dfplot7, dfplot1, dfplot15, dfplot11,
                  dfplot25, dfplot5, dfplot39, dfplot31,
                  dfplot9, dfplot27, dfplot17, dfplot3,
                  dfplot35, dfplot29, dfplot33, dfplot23)

figure3 <- ggplot(test.df, aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + geom_point() +
  geom_pointrange(aes(ymin = ylo, ymax = yhi)) + theme_fivethirtyeight()  + coord_flip() + geom_hline(aes(x=0), lty=2, yintercept = 0) + 
  labs(title = "Figure 3: Perceptions of \nprotest activities' incivility", 
       caption = "Note: Bars represent 95% confidence intervals; Corresponding regression table can be found in Appendix B",
       y = "Perception of incivility (low to high)", x = " ") + 
  facet_wrap( ~ type, ncol = 2, scales = "free_y", strip.position = "top")
ggsave("figure3.jpg", device = "jpeg", dpi = 320, width = 7.5, height = 10, units = "in")
figure3

#appendix for white respondents
app.df <- rbind(dfplot38, dfplot20, dfplot14, dfplot22,
                 dfplot8, dfplot1, dfplot15, dfplot12,
                 dfplot26, dfplot6, dfplot40, dfplot32,
                 dfplot10, dfplot28, dfplot18, dfplot4,
                 dfplot36, dfplot30, dfplot34, dfplot24)

app.fig.1 <- ggplot(app.df, aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + geom_point() +
  geom_pointrange(aes(ymin = ylo, ymax = yhi)) + theme_fivethirtyeight()  + coord_flip() + geom_hline(aes(x=0), lty=2, yintercept = 0) + 
  labs(title = "White perceptions of \nprotest activities' incivility", 
       caption = "Note: Bars represent 95% confidence intervals; Corresponding regression table can be found in Appendix B",
       y = "Perception of incivility (low to high)", x = " ") + 
  facet_wrap( ~ type, nrow = 2, scales = "free_y", strip.position = "top")
ggsave("figapp1.jpg", device = "jpeg", dpi = 320, width = 7.5, height = 10, units = "in")
app.fig.1

# app.df <- rbind(dfplot37, dfplot38, dfplot19, dfplot20, dfplot13, dfplot14, dfplot21, dfplot22,
#                   dfplot7, dfplot8, dfplot1, dfplot2, dfplot15, dfplot16, dfplot11, dfplot12,
#                   dfplot25, dfplot26, dfplot5, dfplot6, dfplot39, dfplot40, dfplot31, dfplot32,
#                   dfplot9, dfplot10, dfplot27, dfplot28, dfplot17, dfplot18, dfplot3, dfplot4,
#                   dfplot35, dfplot36, dfplot29, dfplot30, dfplot33, dfplot34, dfplot23, dfplot24)

# Create first half of figure
# figure1a <- filter(app.df, type=="Less Disruptive") %>% 
#    ggplot(aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + 
#    geom_point() +
#    geom_pointrange(aes(ymin = ylo, ymax = yhi)) + 
#    theme_fivethirtyeight() + 
#    coord_flip() + 
#    geom_hline(lty=2, yintercept = 0) + 
#    ylim(-0.13,0.07) +
#    facet_wrap( ~ race, ncol = 2, strip.position = "top")

# Create second half of figure
# Note only the lower half contains the caption
# figure1b <- filter(app.df, type=="More Disruptive") %>% 
#    ggplot(aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + 
#    geom_point() +
#    geom_pointrange(aes(ymin = ylo, ymax = yhi)) + 
#    theme_fivethirtyeight() + 
#    coord_flip() + 
#    geom_hline(lty=2, yintercept = 0) + 
#    labs(caption = "Note: Bars represent 95% confidence intervals; Corresponding regression table can be found in Appendix B",
#         y = "Perception of incivility (low to high)") + 
#    ylim(-0.13,0.07) +
#    facet_wrap( ~ race, ncol = 2, strip.position = "top")

# Combine figure halves using ggarrange as two rows, add labels, save as jpg
# ggarrange(figure1a, figure1b, nrow=2, labels=c("Less Disruptive","More Disruptive")) + 
# ggsave("figure1.jpg", device = "jpeg", dpi = 320, width = 7.5, height = 9.5, units = "in")


#Figure 4: participation in protest
reg41 <- lm(picket.participate ~ condition, data = ds.black)
reg42 <- lm(chant.participate ~ condition, data = ds.black)
reg43 <- lm(march.participate ~ condition, data = ds.black)
reg44 <- lm(punch.participate ~ condition, data = ds.black)
reg45 <- lm(interrupt.participate ~ condition, data = ds.black)
reg46 <- lm(parade.participate ~ condition, data = ds.black)
reg47 <- lm(knee.participate ~ condition, data = ds.black)
reg48 <- lm(petition.participate ~ condition, data = ds.black)
reg49 <- lm(property.participate ~ condition, data = ds.black)
reg50 <- lm(throw.participate ~ condition, data = ds.black)
reg51 <- lm(sitin.participate ~ condition, data = ds.black)
reg52 <- lm(blocktraffic.participate ~ condition, data = ds.black)
reg53 <- lm(occupy.participate ~ condition, data = ds.black)
reg54 <- lm(graffiti.participate ~ condition, data = ds.black)
reg55 <- lm(camp.participate ~ condition, data = ds.black)
reg56 <- lm(lawsuit.participate ~ condition, data = ds.black)
reg57 <- lm(boycott.participate ~ condition, data = ds.black)
reg58 <- lm(vigil.participate ~ condition, data = ds.black)
reg59 <- lm(threat.participate ~ condition, data = ds.black)
reg60 <- lm(leaflet.participate ~ condition, data = ds.black)

reg61 <- lm(picket.participate ~ condition, data = ds.white)
reg62 <- lm(chant.participate ~ condition, data = ds.white)
reg63 <- lm(march.participate ~ condition, data = ds.white)
reg64 <- lm(punch.participate ~ condition, data = ds.white)
reg65 <- lm(interrupt.participate ~ condition, data = ds.white)
reg66 <- lm(parade.participate ~ condition, data = ds.white)
reg67 <- lm(knee.participate ~ condition, data = ds.white)
reg68 <- lm(petition.participate ~ condition, data = ds.white)
reg69 <- lm(property.participate ~ condition, data = ds.white)
reg70 <- lm(throw.participate ~ condition, data = ds.white)
reg71 <- lm(sitin.participate ~ condition, data = ds.white)
reg72 <- lm(blocktraffic.participate ~ condition, data = ds.white)
reg73 <- lm(occupy.participate ~ condition, data = ds.white)
reg74 <- lm(graffiti.participate ~ condition, data = ds.white)
reg75 <- lm(camp.participate ~ condition, data = ds.white)
reg76 <- lm(lawsuit.participate ~ condition, data = ds.white)
reg77 <- lm(boycott.participate ~ condition, data = ds.white)
reg78 <- lm(vigil.participate ~ condition, data = ds.white)
reg79 <- lm(threat.participate ~ condition, data = ds.white)
reg80 <- lm(leaflet.participate ~ condition, data = ds.white)

stargazer(reg44, reg45, reg49, reg50, reg52, reg53, reg54, reg59, type = "text", out = "blackparticipate.html")
stargazer(reg64, reg65, reg69, reg70, reg72, reg73, reg74, reg79, type = "text", out = "whiteparticipate.html")

p.value.list.3 <- c(lmp(reg44), lmp(reg45), lmp(reg49), lmp(reg50), lmp(reg52), lmp(reg53), lmp(reg54), lmp(reg59))
p.value.list.4 <- c(lmp(reg64), lmp(reg65), lmp(reg69), lmp(reg70), lmp(reg72), lmp(reg73), lmp(reg74), lmp(reg79))

round(p.value.list.3, digits = 4)
round(p.value.list.4, digits = 4)

multi.correct.3 <- p.adjust(p.value.list.3, method = "bonferroni", n = 8)
multi.correct.4 <- p.adjust(p.value.list.4, method = "bonferroni", n = 8)

round(multi.correct.3, digits = 4)
round(multi.correct.4, digits = 4)

modelcoef = summary(reg41)$coefficients[1:length(reg41$coefficients), 1]
modelse = as.vector(coeftest(reg41)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Picket Lines***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot41 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot41 = dfplot41[-c(1),]

modelcoef = summary(reg61)$coefficients[1:length(reg61$coefficients), 1]
modelse = as.vector(coeftest(reg61)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Picket Lines***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot42 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot42 = dfplot42[-c(1),]

modelcoef = summary(reg42)$coefficients[1:length(reg42$coefficients), 1]
modelse = as.vector(coeftest(reg42)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Chanting***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot43 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot43 = dfplot43[-c(1),]

modelcoef = summary(reg62)$coefficients[1:length(reg62$coefficients), 1]
modelse = as.vector(coeftest(reg62)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Chanting***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot44 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot44 = dfplot44[-c(1),]

modelcoef = summary(reg43)$coefficients[1:length(reg43$coefficients), 1]
modelse = as.vector(coeftest(reg43)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Marching***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot45 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot45 = dfplot45[-c(1),]

modelcoef = summary(reg63)$coefficients[1:length(reg63$coefficients), 1]
modelse = as.vector(coeftest(reg63)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Marching***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot46 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot46 = dfplot46[-c(1),]

modelcoef = summary(reg44)$coefficients[1:length(reg44$coefficients), 1]
modelse = as.vector(coeftest(reg44)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Punching**")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot47 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot47 = dfplot47[-c(1),]

modelcoef = summary(reg64)$coefficients[1:length(reg64$coefficients), 1]
modelse = as.vector(coeftest(reg64)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Punching")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot48 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot48 = dfplot48[-c(1),]

modelcoef = summary(reg45)$coefficients[1:length(reg45$coefficients), 1]
modelse = as.vector(coeftest(reg45)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Interrupting public event***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot49 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot49 = dfplot49[-c(1),]

modelcoef = summary(reg65)$coefficients[1:length(reg65$coefficients), 1]
modelse = as.vector(coeftest(reg65)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Interrupting public event***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot50 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot50 = dfplot50[-c(1),]

modelcoef = summary(reg46)$coefficients[1:length(reg46$coefficients), 1]
modelse = as.vector(coeftest(reg46)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Parades*")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot51 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot51 = dfplot51[-c(1),]

modelcoef = summary(reg66)$coefficients[1:length(reg66$coefficients), 1]
modelse = as.vector(coeftest(reg66)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Parades***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot52 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot52 = dfplot52[-c(1),]

modelcoef = summary(reg47)$coefficients[1:length(reg47$coefficients), 1]
modelse = as.vector(coeftest(reg47)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Taking a knee*")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot53 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot53 = dfplot53[-c(1),]

modelcoef = summary(reg67)$coefficients[1:length(reg67$coefficients), 1]
modelse = as.vector(coeftest(reg67)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Taking a knee**")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot54 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot54 = dfplot54[-c(1),]

modelcoef = summary(reg48)$coefficients[1:length(reg48$coefficients), 1]
modelse = as.vector(coeftest(reg48)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Petitions")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot55 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot55 = dfplot55[-c(1),]

modelcoef = summary(reg68)$coefficients[1:length(reg68$coefficients), 1]
modelse = as.vector(coeftest(reg68)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Petitions**")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot56 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot56 = dfplot56[-c(1),]

modelcoef = summary(reg49)$coefficients[1:length(reg49$coefficients), 1]
modelse = as.vector(coeftest(reg49)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Damaging property***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot57 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot57 = dfplot57[-c(1),]

modelcoef = summary(reg69)$coefficients[1:length(reg69$coefficients), 1]
modelse = as.vector(coeftest(reg69)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Damaging property")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot58 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot58 = dfplot58[-c(1),]

modelcoef = summary(reg50)$coefficients[1:length(reg50$coefficients), 1]
modelse = as.vector(coeftest(reg50)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Throwing objects***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot59 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot59 = dfplot59[-c(1),]

modelcoef = summary(reg70)$coefficients[1:length(reg70$coefficients), 1]
modelse = as.vector(coeftest(reg70)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Throwing objects")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot60 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot60 = dfplot60[-c(1),]

modelcoef = summary(reg51)$coefficients[1:length(reg51$coefficients), 1]
modelse = as.vector(coeftest(reg51)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Sit-ins**")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot61 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot61 = dfplot61[-c(1),]

modelcoef = summary(reg71)$coefficients[1:length(reg71$coefficients), 1]
modelse = as.vector(coeftest(reg71)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Sit-ins**")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot62 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot62 = dfplot62[-c(1),]

modelcoef = summary(reg52)$coefficients[1:length(reg52$coefficients), 1]
modelse = as.vector(coeftest(reg52)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Blocking traffic***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot63 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot63 = dfplot63[-c(1),]

modelcoef = summary(reg72)$coefficients[1:length(reg72$coefficients), 1]
modelse = as.vector(coeftest(reg72)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Blocking traffic")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot64 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot64 = dfplot64[-c(1),]

modelcoef = summary(reg53)$coefficients[1:length(reg53$coefficients), 1]
modelse = as.vector(coeftest(reg53)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Occupying private property")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot65 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot65 = dfplot65[-c(1),]

modelcoef = summary(reg73)$coefficients[1:length(reg73$coefficients), 1]
modelse = as.vector(coeftest(reg73)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Occupying private property*")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot66 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot66 = dfplot66[-c(1),]

modelcoef = summary(reg54)$coefficients[1:length(reg54$coefficients), 1]
modelse = as.vector(coeftest(reg54)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Graffiti**")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot67 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot67 = dfplot67[-c(1),]

modelcoef = summary(reg74)$coefficients[1:length(reg74$coefficients), 1]
modelse = as.vector(coeftest(reg74)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Graffiti**")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot68 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot68 = dfplot68[-c(1),]

modelcoef = summary(reg55)$coefficients[1:length(reg55$coefficients), 1]
modelse = as.vector(coeftest(reg55)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Camping on public property***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot69 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot69 = dfplot69[-c(1),]

modelcoef = summary(reg75)$coefficients[1:length(reg75$coefficients), 1]
modelse = as.vector(coeftest(reg75)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Camping on public property***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot70 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot70 = dfplot70[-c(1),]

modelcoef = summary(reg56)$coefficients[1:length(reg56$coefficients), 1]
modelse = as.vector(coeftest(reg56)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Lawsuits")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot71 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot71 = dfplot71[-c(1),]

modelcoef = summary(reg76)$coefficients[1:length(reg76$coefficients), 1]
modelse = as.vector(coeftest(reg76)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Lawsuits***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot72 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot72 = dfplot72[-c(1),]

modelcoef = summary(reg57)$coefficients[1:length(reg57$coefficients), 1]
modelse = as.vector(coeftest(reg57)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Boycotts")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot73 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot73 = dfplot73[-c(1),]

modelcoef = summary(reg77)$coefficients[1:length(reg77$coefficients), 1]
modelse = as.vector(coeftest(reg77)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Boycotts***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot74 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot74 = dfplot74[-c(1),]

modelcoef = summary(reg58)$coefficients[1:length(reg58$coefficients), 1]
modelse = as.vector(coeftest(reg58)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Candlelight vigils")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot75 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot75 = dfplot75[-c(1),]

modelcoef = summary(reg78)$coefficients[1:length(reg78$coefficients), 1]
modelse = as.vector(coeftest(reg78)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Candlelight vigils**")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot76 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot76 = dfplot76[-c(1),]

modelcoef = summary(reg59)$coefficients[1:length(reg59$coefficients), 1]
modelse = as.vector(coeftest(reg59)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Verbal threats***")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "More Disruptive"
dfplot77 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot77 = dfplot77[-c(1),]

modelcoef = summary(reg79)$coefficients[1:length(reg79$coefficients), 1]
modelse = as.vector(coeftest(reg79)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Verbal threats")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "More Disruptive"
dfplot78 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot78 = dfplot78[-c(1),]

modelcoef = summary(reg60)$coefficients[1:length(reg60$coefficients), 1]
modelse = as.vector(coeftest(reg60)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.black))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.black))*(modelse)
names = c("Intercept", "Leaflets**")
names = factor(names, levels = unique(names))
race = c("Intercept", "Black")
type = "Less Disruptive"
dfplot79 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot79 = dfplot79[-c(1),]

modelcoef = summary(reg80)$coefficients[1:length(reg80$coefficients), 1]
modelse = as.vector(coeftest(reg80)[, 2])
ylo = modelcoef - qt(.975, nrow(ds.white))*(modelse)
yhi = modelcoef + qt(.975, nrow(ds.white))*(modelse)
names = c("Intercept", "Leaflets***")
names = factor(names, levels = unique(names))
race = c("Intercept", "White")
type = "Less Disruptive"
dfplot80 = data.frame(names, modelcoef, modelse, ylo, yhi, race, type)
dfplot80 = dfplot80[-c(1),]

test.df2 <- rbind(dfplot77, dfplot59, dfplot53, dfplot61,
                  dfplot47, dfplot41, dfplot55, dfplot51, 
                  dfplot65, dfplot45, dfplot79, dfplot71, 
                  dfplot49, dfplot67, dfplot57, dfplot43, 
                  dfplot75, dfplot69, dfplot73, dfplot63)

figure4 <- ggplot(test.df2, aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + geom_point() +
  geom_pointrange(aes(ymin = ylo, ymax = yhi)) + theme_fivethirtyeight()  + coord_flip() + geom_hline(aes(x=0), lty=2, yintercept = 0) + 
  labs(title = "Figure 4: Likelihood to \nparticipate in protest activities", 
       caption = "Note: Bars represent 95% confidence intervals; Corresponding regression table can be found in Appendix B",
       y = "Likelihood to participate (low to high)", x = " ") + 
  facet_wrap( ~ type, ncol = 2, scales = "free_y", strip.position = "top")
ggsave("figure4.jpg", device = "jpeg", dpi = 320, width = 7.5, height = 10, units = "in")
figure4

#appendix for white respondents
app.df2 <- rbind(dfplot78, dfplot60, dfplot54, dfplot62,
                  dfplot48, dfplot42, dfplot56, dfplot52, 
                  dfplot66, dfplot46, dfplot80, dfplot72, 
                  dfplot50, dfplot68, dfplot58, dfplot44, 
                  dfplot76, dfplot70, dfplot74, dfplot64)

app.fig.2 <- ggplot(app.df2, aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + geom_point() +
  geom_pointrange(aes(ymin = ylo, ymax = yhi)) + theme_fivethirtyeight()  + coord_flip() + geom_hline(aes(x=0), lty=2, yintercept = 0) + 
  labs(title = "White intentions re: protest activities", 
       caption = "Note: Bars represent 95% confidence intervals; Corresponding regression table can be found in Appendix B",
       y = "Perception of incivility (low to high)", x = " ") + 
  facet_wrap( ~ type, nrow = 2, scales = "free_y", strip.position = "top")
ggsave("figapp2.jpg", device = "jpeg", dpi = 320, width = 7.5, height = 10, units = "in")
app.fig.2

# test.df2 <- rbind(dfplot77, dfplot78, dfplot59, dfplot60, dfplot53, dfplot54, dfplot61, dfplot62,
#                  dfplot47, dfplot48, dfplot41, dfplot42, dfplot55, dfplot56, dfplot51, dfplot52,
#                  dfplot65, dfplot66, dfplot45, dfplot46, dfplot79, dfplot80, dfplot71, dfplot72,
#                  dfplot49, dfplot50, dfplot67, dfplot68, dfplot57, dfplot58, dfplot43, dfplot44,
#                  dfplot75, dfplot76, dfplot69, dfplot70, dfplot73, dfplot74, dfplot63, dfplot64)


# figure2a <- filter(test.df2, type=="Less Disruptive") %>% 
#   ggplot(aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + 
#   geom_point() +
#   geom_pointrange(aes(ymin = ylo, ymax = yhi)) + 
#   theme_fivethirtyeight() + 
#   coord_flip() + 
#   geom_hline(lty=2, yintercept = 0) + 
#   ylim(-0.07,0.14) +
#   facet_wrap( ~ race, ncol = 2, strip.position = "top")

# Create second half of figure
# Note only the lower half contains the caption
# figure2b <- filter(test.df2, type=="More Disruptive") %>% 
#   ggplot(aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + 
#   geom_point() +
#   geom_pointrange(aes(ymin = ylo, ymax = yhi)) + 
#   theme_fivethirtyeight() + 
#   coord_flip() + 
#   geom_hline(lty=2, yintercept = 0) + 
#   labs(caption = "Note: Bars represent 95% confidence intervals; Corresponding regression table can be found in Appendix B",
#        y = "Likelihood to participate (low to high)") + 
#   ylim(-0.07,0.14) +
#   facet_wrap( ~ race, ncol = 2, strip.position = "top")

# Combine figure halves using ggarrange as two rows, add labels, save as jpg
# ggarrange(figure2a, figure2b, nrow=2, labels=c("Less Disruptive","More Disruptive")) + 
#   ggsave("figure2.jpg", device = "jpeg", dpi = 320, width = 7.5, height = 9.5, units = "in")

#list experiments
ds.white$list.control.1 <- ds.white$list.control.1 - 1
ds.white$list.control.2 <- ds.white$list.control.2 - 1
ds.white$list.control.3 <- ds.white$list.control.3 - 1
ds.white$list.treat.1 <- ds.white$list.treat.1 - 1
ds.white$list.treat.2 <- ds.white$list.treat.2 - 1
ds.white$list.treat.3 <- ds.white$list.treat.3 - 1
ds.black$list.control.1 <- ds.black$list.control.1 - 1
ds.black$list.control.2 <- ds.black$list.control.2 - 1
ds.black$list.control.3 <- ds.black$list.control.3 - 1
ds.black$list.treat.1 <- ds.black$list.treat.1 - 1
ds.black$list.treat.2 <- ds.black$list.treat.2 - 1
ds.black$list.treat.3 <- ds.black$list.treat.3 - 1

ds.white.list.control.1 <- dplyr::filter(ds.white, LEC1 == "control")
ds.white.list.control.2 <- dplyr::filter(ds.white, LEC2 == "control")
ds.white.list.control.3 <- dplyr::filter(ds.white, LEC3 == "control")
ds.white.list.treat.1 <- dplyr::filter(ds.white, LEC1 == "treatment")
ds.white.list.treat.2 <- dplyr::filter(ds.white, LEC2 == "treatment")
ds.white.list.treat.3 <- dplyr::filter(ds.white, LEC3 == "treatment")
ds.black.list.control.1 <- dplyr::filter(ds.black, LEC1 == "control")
ds.black.list.control.2 <- dplyr::filter(ds.black, LEC2 == "control")
ds.black.list.control.3 <- dplyr::filter(ds.black, LEC3 == "control")
ds.black.list.treat.1 <- dplyr::filter(ds.black, LEC1 == "treatment")
ds.black.list.treat.2 <- dplyr::filter(ds.black, LEC2 == "treatment")
ds.black.list.treat.3 <- dplyr::filter(ds.black, LEC3 == "treatment") 

LE.black.group.C.1 <- dplyr::filter(ds.black.list.control.1, condition == "treatment")
LE.black.group.C.2 <- dplyr::filter(ds.black.list.control.2, condition == "treatment")
LE.black.group.C.3 <- dplyr::filter(ds.black.list.control.3, condition == "treatment")
LE.white.group.C.1 <- dplyr::filter(ds.white.list.control.1, condition == "treatment")
LE.white.group.C.2 <- dplyr::filter(ds.white.list.control.2, condition == "treatment")
LE.white.group.C.3 <- dplyr::filter(ds.white.list.control.3, condition == "treatment")

LE.black.group.A.1 <- dplyr::filter(ds.black.list.treat.1, condition == "treatment")
LE.black.group.A.2 <- dplyr::filter(ds.black.list.treat.2, condition == "treatment")
LE.black.group.A.3 <- dplyr::filter(ds.black.list.treat.3, condition == "treatment")
LE.white.group.A.1 <- dplyr::filter(ds.white.list.treat.1, condition == "treatment")
LE.white.group.A.2 <- dplyr::filter(ds.white.list.treat.2, condition == "treatment")
LE.white.group.A.3 <- dplyr::filter(ds.white.list.treat.3, condition == "treatment")

LE.black.group.B.1 <- dplyr::filter(ds.black.list.treat.1, condition == "control")
LE.black.group.B.2 <- dplyr::filter(ds.black.list.treat.2, condition == "control")
LE.black.group.B.3 <- dplyr::filter(ds.black.list.treat.3, condition == "control")
LE.white.group.B.1 <- dplyr::filter(ds.white.list.treat.1, condition == "control")
LE.white.group.B.2 <- dplyr::filter(ds.white.list.treat.2, condition == "control")
LE.white.group.B.3 <- dplyr::filter(ds.white.list.treat.3, condition == "control")

LE.black.group.D.1 <- dplyr::filter(ds.black.list.control.1, condition == "control")
LE.black.group.D.2 <- dplyr::filter(ds.black.list.control.2, condition == "control")
LE.black.group.D.3 <- dplyr::filter(ds.black.list.control.3, condition == "control")
LE.white.group.D.1 <- dplyr::filter(ds.white.list.control.1, condition == "control")
LE.white.group.D.2 <- dplyr::filter(ds.white.list.control.2, condition == "control")
LE.white.group.D.3 <- dplyr::filter(ds.white.list.control.3, condition == "control")

#testing hypotheses
#Hypotheses 2 and 3
#Blocking traffic
t.test(LE.black.group.A.1$list.treat.1, LE.black.group.C.1$list.control.1)
t.test(LE.white.group.A.1$list.treat.1, LE.white.group.C.1$list.control.1)
#Damaging property
t.test(LE.black.group.A.2$list.treat.2, LE.black.group.C.2$list.control.2)
t.test(LE.white.group.A.2$list.treat.2, LE.white.group.C.2$list.control.2)
#Throwing objects
t.test(LE.black.group.A.3$list.treat.3, LE.black.group.C.3$list.control.3)
t.test(LE.white.group.A.3$list.treat.3, LE.white.group.C.3$list.control.3)

#Hypothesis 1
#Blocking traffic
t.test(LE.black.group.B.1$list.treat.1, LE.black.group.D.1$list.control.1)
t.test(LE.white.group.B.1$list.treat.1, LE.white.group.D.1$list.control.1)
#Damaging property
t.test(LE.black.group.B.2$list.treat.2, LE.black.group.D.2$list.control.2)
t.test(LE.white.group.B.2$list.treat.2, LE.white.group.D.2$list.control.2)
#Throwing objects
t.test(LE.black.group.B.3$list.treat.3, LE.black.group.D.3$list.control.3)
t.test(LE.white.group.B.3$list.treat.3, LE.white.group.D.3$list.control.3)

#looking for some interaction effects

#reg4 <- lm(punch.uncivil ~ condition, data = ds.black)
#reg5 <- lm(interrupt.uncivil ~ condition, data = ds.black)
#reg9 <- lm(property.uncivil ~ condition, data = ds.black)
#reg10 <- lm(throw.uncivil ~ condition, data = ds.black)
#reg12 <- lm(blocktraffic.uncivil ~ condition, data = ds.black)
#reg13 <- lm(occupy.uncivil ~ condition, data = ds.black)
#reg14 <- lm(graffiti.uncivil ~ condition, data = ds.black)
#reg19 <- lm(threat.uncivil ~ condition, data = ds.black)

reg81 <- lm(punch.uncivil ~ condition*linkedfate, data = ds.black)
reg82 <- lm(interrupt.uncivil ~ condition*linkedfate, data = ds.black)
reg83 <- lm(property.uncivil ~ condition*linkedfate, data = ds.black)
reg84 <- lm(throw.uncivil ~ condition*linkedfate, data = ds.black)
reg85 <- lm(blocktraffic.uncivil ~ condition*linkedfate, data = ds.black)
reg86 <- lm(occupy.uncivil ~ condition*linkedfate, data = ds.black)
reg87 <- lm(graffiti.uncivil ~ condition*linkedfate, data = ds.black)
reg88 <- lm(threat.uncivil ~ condition*linkedfate, data = ds.black)


stargazer(reg81, reg82, reg83, reg84, type = "text", out = "g1.html")
stargazer(reg85, reg86, reg87, reg88, type = "text", out = "g2.html")

reg89 <- lm(punch.participate ~ condition*linkedfate, data = ds.black)
reg90 <- lm(interrupt.participate ~ condition*linkedfate, data = ds.black)
reg91 <- lm(property.participate ~ condition*linkedfate, data = ds.black)
reg92 <- lm(throw.participate ~ condition*linkedfate, data = ds.black)
reg93 <- lm(blocktraffic.participate ~ condition*linkedfate, data = ds.black)
reg94 <- lm(occupy.participate ~ condition*linkedfate, data = ds.black)
reg95 <- lm(graffiti.participate ~ condition*linkedfate, data = ds.black)
reg96 <- lm(threat.participate ~ condition*linkedfate, data = ds.black)

stargazer(reg89, reg90, reg91, reg92, type = "text", out = "g3.html")
stargazer(reg93, reg94, reg95, reg96, type = "text", out = "g4.html")

reg97 <- lm(punch.uncivil ~ condition*dominance, data = ds.white)
reg98 <- lm(interrupt.uncivil ~ condition*dominance, data = ds.white)
reg99 <- lm(property.uncivil ~ condition*dominance, data = ds.white)
reg100 <- lm(throw.uncivil ~ condition*dominance, data = ds.white)
reg101 <- lm(blocktraffic.uncivil ~ condition*dominance, data = ds.white)
reg102 <- lm(occupy.uncivil ~ condition*dominance, data = ds.white)
reg103 <- lm(graffiti.uncivil ~ condition*dominance, data = ds.white)
reg104 <- lm(threat.uncivil ~ condition*dominance, data = ds.white)

stargazer(reg97, reg98, reg99, reg100, type = "text")
stargazer(reg101, reg102, reg103, reg104, type = "text")

reg105 <- lm(punch.uncivil ~ condition*fire.anger, data = ds.white)
reg106 <- lm(interrupt.uncivil ~ condition*fire.anger, data = ds.white)
reg107 <- lm(property.uncivil ~ condition*fire.anger, data = ds.white)
reg108 <- lm(throw.uncivil ~ condition*fire.anger, data = ds.white)
reg109 <- lm(blocktraffic.uncivil ~ condition*fire.anger, data = ds.white)
reg110 <- lm(occupy.uncivil ~ condition*fire.anger, data = ds.white)
reg111 <- lm(graffiti.uncivil ~ condition*fire.anger, data = ds.white)
reg112 <- lm(threat.uncivil ~ condition*fire.anger, data = ds.white)

stargazer(reg105, reg106, reg107, reg108, type = "text")
stargazer(reg109, reg110, reg111, reg112, type = "text")

reg113 <- lm(punch.uncivil ~ condition*fire.fear, data = ds.white)
reg114 <- lm(interrupt.uncivil ~ condition*fire.fear, data = ds.white)
reg115 <- lm(property.uncivil ~ condition*fire.fear, data = ds.white)
reg116 <- lm(throw.uncivil ~ condition*fire.fear, data = ds.white)
reg117 <- lm(blocktraffic.uncivil ~ condition*fire.fear, data = ds.white)
reg118 <- lm(occupy.uncivil ~ condition*fire.fear, data = ds.white)
reg119 <- lm(graffiti.uncivil ~ condition*fire.fear, data = ds.white)
reg120 <- lm(threat.uncivil ~ condition*fire.fear, data = ds.white)

stargazer(reg113, reg114, reg115, reg116, type = "text")
stargazer(reg117, reg118, reg119, reg120, type = "text")

reg121 <- lm(punch.uncivil ~ condition*fire.problems, data = ds.white)
reg122 <- lm(interrupt.uncivil ~ condition*fire.problems, data = ds.white)
reg123 <- lm(property.uncivil ~ condition*fire.problems, data = ds.white)
reg124 <- lm(throw.uncivil ~ condition*fire.problems, data = ds.white)
reg125 <- lm(blocktraffic.uncivil ~ condition*fire.problems, data = ds.white)
reg126 <- lm(occupy.uncivil ~ condition*fire.problems, data = ds.white)
reg127 <- lm(graffiti.uncivil ~ condition*fire.problems, data = ds.white)
reg128 <- lm(threat.uncivil ~ condition*fire.problems, data = ds.white)

stargazer(reg121, reg122, reg123, reg124, type = "text")
stargazer(reg125, reg126, reg127, reg128, type = "text")

reg129 <- lm(punch.uncivil ~ condition*fire.white.advantage, data = ds.white)
reg130 <- lm(interrupt.uncivil ~ condition*fire.white.advantage, data = ds.white)
reg131 <- lm(property.uncivil ~ condition*fire.white.advantage, data = ds.white)
reg132 <- lm(throw.uncivil ~ condition*fire.white.advantage, data = ds.white)
reg133 <- lm(blocktraffic.uncivil ~ condition*fire.white.advantage, data = ds.white)
reg134 <- lm(occupy.uncivil ~ condition*fire.white.advantage, data = ds.white)
reg135 <- lm(graffiti.uncivil ~ condition*fire.white.advantage, data = ds.white)
reg136 <- lm(threat.uncivil ~ condition*fire.white.advantage, data = ds.white)

stargazer(reg129, reg130, reg131, reg132, type = "text")
stargazer(reg133, reg134, reg135, reg136, type = "text")

#participation and racial attitudes
reg137 <- lm(punch.participate ~ condition*dominance, data = ds.white)
reg138 <- lm(interrupt.participate ~ condition*dominance, data = ds.white)
reg139 <- lm(property.participate ~ condition*dominance, data = ds.white)
reg140 <- lm(throw.participate ~ condition*dominance, data = ds.white)
reg141 <- lm(blocktraffic.participate ~ condition*dominance, data = ds.white)
reg142 <- lm(occupy.participate ~ condition*dominance, data = ds.white)
reg143 <- lm(graffiti.participate ~ condition*dominance, data = ds.white)
reg144 <- lm(threat.participate ~ condition*dominance, data = ds.white)

stargazer(reg137, reg138, reg139, reg140, type = "text")
stargazer(reg141, reg142, reg143, reg144, type = "text")

#ANGER ABOUT RACIAL INEQUALITY WORKS TO INCREASE PARTICIPATION!
reg145 <- lm(punch.participate ~ condition*fire.anger, data = ds.white)
reg146 <- lm(interrupt.participate ~ condition*fire.anger, data = ds.white)
reg147 <- lm(property.participate ~ condition*fire.anger, data = ds.white)
reg148 <- lm(throw.participate ~ condition*fire.anger, data = ds.white)
reg149 <- lm(blocktraffic.participate ~ condition*fire.anger, data = ds.white)
reg150 <- lm(occupy.participate ~ condition*fire.anger, data = ds.white)
reg151 <- lm(graffiti.participate ~ condition*fire.anger, data = ds.white)
reg152 <- lm(threat.participate ~ condition*fire.anger, data = ds.white)


stargazer(reg145, reg146, reg147, reg148, type = "text", out = "tableanger.html")
stargazer(reg149, reg150, reg151, reg152, type = "text", out = "tableanger2.html")

reg153 <- lm(punch.participate ~ condition*fire.fear, data = ds.white)
reg154 <- lm(interrupt.participate ~ condition*fire.fear, data = ds.white)
reg155 <- lm(property.participate ~ condition*fire.fear, data = ds.white)
reg156 <- lm(throw.participate ~ condition*fire.fear, data = ds.white)
reg157 <- lm(blocktraffic.participate ~ condition*fire.fear, data = ds.white)
reg158 <- lm(occupy.participate ~ condition*fire.fear, data = ds.white)
reg159 <- lm(graffiti.participate ~ condition*fire.fear, data = ds.white)
reg160 <- lm(threat.participate ~ condition*fire.fear, data = ds.white)

stargazer(reg153, reg154, reg155, reg156, type = "text")
stargazer(reg157, reg158, reg159, reg160, type = "text")

#Thinking that race issues are rare lead white people to not want to participate in some activities!
reg161 <- lm(punch.participate ~ condition*fire.problems, data = ds.white)
reg162 <- lm(interrupt.participate ~ condition*fire.problems, data = ds.white)
reg163 <- lm(property.participate ~ condition*fire.problems, data = ds.white)
reg164 <- lm(throw.participate ~ condition*fire.problems, data = ds.white)
reg165 <- lm(blocktraffic.participate ~ condition*fire.problems, data = ds.white)
reg166 <- lm(occupy.participate ~ condition*fire.problems, data = ds.white)
reg167 <- lm(graffiti.participate ~ condition*fire.problems, data = ds.white)
reg168 <- lm(threat.participate ~ condition*fire.problems, data = ds.white)

stargazer(reg161, reg162, reg163, reg164, type = "text")
stargazer(reg165, reg166, reg167, reg168, type = "text")

reg169 <- lm(punch.participate ~ condition*fire.white.advantage, data = ds.white)
reg170 <- lm(interrupt.participate ~ condition*fire.white.advantage, data = ds.white)
reg171 <- lm(property.participate ~ condition*fire.white.advantage, data = ds.white)
reg172 <- lm(throw.participate ~ condition*fire.white.advantage, data = ds.white)
reg173 <- lm(blocktraffic.participate ~ condition*fire.white.advantage, data = ds.white)
reg174 <- lm(occupy.participate ~ condition*fire.white.advantage, data = ds.white)
reg175 <- lm(graffiti.participate ~ condition*fire.white.advantage, data = ds.white)
reg176 <- lm(threat.participate ~ condition*fire.white.advantage, data = ds.white)

stargazer(reg169, reg170, reg171, reg172, type = "text")
stargazer(reg173, reg174, reg175, reg176, type = "text")

#black age cohorts moderation
reg177 <- lm(punch.uncivil ~ condition*age.demo, data = ds.black)
reg178 <- lm(interrupt.uncivil ~ condition*age.demo, data = ds.black)
reg179 <- lm(property.uncivil ~ condition*age.demo, data = ds.black)
reg180 <- lm(throw.uncivil ~ condition*age.demo, data = ds.black)
reg181 <- lm(blocktraffic.uncivil ~ condition*age.demo, data = ds.black)
reg182 <- lm(occupy.uncivil ~ condition*age.demo, data = ds.black)
reg183 <- lm(graffiti.uncivil ~ condition*age.demo, data = ds.black)
reg184 <- lm(threat.uncivil ~ condition*age.demo, data = ds.black)

stargazer(reg177, reg178, reg179, reg180, type = "text", out = "g5.html")
stargazer(reg181, reg182, reg183, reg184, type = "text", out = "g6.html")

reg185 <- lm(punch.participate ~ condition*age.demo, data = ds.black)
reg186 <- lm(interrupt.participate ~ condition*age.demo, data = ds.black)
reg187 <- lm(property.participate ~ condition*age.demo, data = ds.black)
reg188 <- lm(throw.participate ~ condition*age.demo, data = ds.black)
reg189 <- lm(blocktraffic.participate ~ condition*age.demo, data = ds.black)
reg190 <- lm(occupy.participate ~ condition*age.demo, data = ds.black)
reg191 <- lm(graffiti.participate ~ condition*age.demo, data = ds.black)
reg192 <- lm(threat.participate ~ condition*age.demo, data = ds.black)

stargazer(reg185, reg186, reg187, reg188, type = "text", out = "g7.html")
stargazer(reg189, reg190, reg191, reg192, type = "text", out = "g8.html")

#black STM
uncivil.stm <- textProcessor(ds.black$uncivil.open, metadata = ds.black)

meta <- uncivil.stm$meta

vocab <- uncivil.stm$vocab

docs <- uncivil.stm$documents

out <- prepDocuments(docs, vocab, meta)

summary(out)

uncivil.PrevFit <- stm(documents = out$documents, vocab = out$vocab, K = 3, max.em.its = 75, 
                        data = out$meta, init.type = "Spectral")

uncivil.PrevFit
labelTopics(uncivil.PrevFit)

plot.STM(uncivil.PrevFit, type = "summary", labeltype = "frex", n = 3)

cloud(uncivil.PrevFit, topic = NULL, type = c("model", "documents"), documents, thresh = 0.9, max.words = 100)

#white STM
uncivil2.stm <- textProcessor(ds.white$uncivil.open, metadata = ds.white)

meta2 <- uncivil2.stm$meta

vocab2 <- uncivil2.stm$vocab

docs2 <- uncivil2.stm$documents

out2 <- prepDocuments(docs2, vocab2, meta2)

summary(out2)

uncivil2.PrevFit <- stm(documents = out2$documents, vocab = out2$vocab, K = 3, max.em.its = 75, 
                       data = out2$meta, init.type = "Spectral")

uncivil2.PrevFit
labelTopics(uncivil2.PrevFit)

plot.STM(uncivil2.PrevFit, type = "summary", labeltype = "frex", n = 3)

cloud(uncivil2.PrevFit, topic = NULL, type = c("model", "documents"), documents, thresh = 0.9, max.words = 100)










 